/*
 * Copyright (c) 2022 Kirky
 * Licensed under the Open Software Licence, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/osl-3.0.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lingeringdream.luciole.slice.fraction;

import com.lingeringdream.luciole.ResourceTable;
import com.lingeringdream.luciole.slice.ResultListSlice;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

/**
 * 主页面-资讯fraction
 *
 * @author Kirky
 * @version 1.2
 * @date 2022/4/2
 */
public class NewsFraction extends Fraction {
    private final AbilitySlice slice;
    private Component newsFraction;


    public NewsFraction(AbilitySlice slice) {
        this.slice = slice;
    }

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        newsFraction = scatter.parse(ResourceTable.Layout_fraction_news, container, false);

        initSearchBar();
        return newsFraction;
    }

    /**
     * 初始化搜索栏
     */
    private void initSearchBar() {
        DependentLayout searchBar = newsFraction.findComponentById(ResourceTable.Id_news_searchbar);
        Text title = newsFraction.findComponentById(ResourceTable.Id_searchBar_title);
        title.setText("请输入感兴趣的内容");
        searchBar.setClickedListener(component -> {
            Intent intent = new Intent();
            intent.setParam("isClassify", false);
            slice.present(new ResultListSlice(), intent);
        });
    }

}